package cc.xuzhi.muggle.common.model;

import lombok.Data;

@Data
public class Result<T> {

    private boolean ok;

    private Integer code;

    private String msg;

    private T data;

    public Result(boolean ok, Integer code, String msg, T data) {
        this.ok = ok;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result<T> ok(T data) {
        return new Result<>(true, 0, "SUCCESS", data);
    }

    public static <T> Result<T> ok() {
        return Result.ok(null);
    }

    public static <T> Result<T> error() {
        return new Result<>(false, 1, "ERROR", null);
    }

    public static <T> Result<T> error(int code, String msg) {
        return new Result<>(false, code, msg, null);
    }

    public static <T> Result<T> error(String msg) {
        return new Result<>(false, 1, msg, null);
    }
}
